song_singers = {} song_names = {} pic_urls = {} song_ids = {}
Event.subscribe("GroupMessageEvent",function(event)
	local msg = tostring(event.message)
	local sender = event.sender
	local group = event.group
	function myerrorhandler(err)
		print("ERROR",err)
	end
	function music(s)
		body = Http.get("http://yz.8848mv.com:8899/v1/search?keyWord=" .. s .. "&offset=1&limit=20")
		return body
	end
	function card(s)
		body = Http.get("http://yz.8848mv.com:8899/v1/getURl?rid=" .. s .. "&br=320k")
		return body
	end	
	function music_tables(s)
		start = xpcall(music,myerrorhandler,s)
		start = tostring(start)
		if start == "true" then
			song_singer = body:gmatch('"artist":"(.-)"')
			pic_url = body:gmatch('"pic":"(.-)"')
			song_name = body:gmatch('"name":"(.-)"')
			song_id = body:gmatch('"rid":(%d+)')
			for i in song_singer do
				table.insert(song_singers,i)
			end
			for i in song_name do
				table.insert(song_names,i)
			end
			for i in pic_url do
				table.insert(pic_urls,i)
			end
			for i in song_id do
				table.insert(song_ids,i)
			end
			rep = Text("")
			for i=1,10 do
				if song_singers[i] == nil then
					break
				end
				list = (i .. ":" .. song_singers[i] .. "-" .. song_names[i] .."\n")
				rep = rep + list
			end
			return (rep .. "回复：#1/2/...")
		else
			return ("ERROR")
		end
	end	
	function music_look(i)
		start = xpcall(card,myerrorhandler,song_ids[i])
		start = tostring(start)
		if start == "true" then
			url = body:match('"url":"(.-)"')
			local __format__ = [[{"app":"com.tencent.structmsg","config":{"autosize":true,"forward":true,"type":"normal"},"desc":"音乐","meta":{"music":{"desc":"%s","jumpUrl":"%s","musicUrl":"%s","preview":"%s","sourceMsgId":"0","source_icon":"","source_url":"","tag":"音乐","title":"%s"}},"prompt":"[分享]%s","ver":"0.0.0.1","view":"music"}]]
			__format__ = string.format(__format__, song_singers[i], url, url, pic_urls[i], song_names[i], song_names[i])
			return (__format__)
		else
			url = "https://other-web-ri01-sycdn.kuwo.cn/ec26fce2849582c411651cdf992af06b/6013fee7/resource/n1/5/67/2779156982.mp3"
			pic_url = "http://pic.51yuansu.com/pic2/cover/00/31/10/5810a32640ac7_610.jpg"
			local __format__ = [[{"app":"com.tencent.structmsg","config":{"autosize":true,"forward":true,"type":"normal"},"desc":"音乐","meta":{"music":{"desc":"%s","jumpUrl":"%s","musicUrl":"%s","preview":"%s","sourceMsgId":"0","source_icon":"","source_url":"","tag":"出错啦！！！","title":"%s"}},"prompt":"[分享]%s","ver":"0.0.0.1","view":"music"}]]
			__format__ = string.format(__format__, "错误", url, url, pic_url, "错误", "错误")
			return (__format__)
		end
	end
	if msg:find("点歌") then
		song_singers = {} song_names = {} pic_urls = {} song_ids = {}
		value = msg:gsub("点歌","")
		res = music_tables(value)
		group:sendMessage(res)
	end
	if msg:find("#%d+") then
		if not msg:find("source") then
			num = msg:gsub("#","")
			num = tonumber(num)
			res = music_look(num)
			group:sendMessage(App(res))
		end
	end	
end)